package com.yangye.springclouddemorabbitmq.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangye
 * @date 2020/08/19
 */
@RestController
@RequestMapping("/send")
@Slf4j
public class MsgSendController {

	String delayQueue = "yangye-delay-queue";

	@Autowired
	private RabbitTemplate rabbitTemplate;

	@RequestMapping("/delay/{msg}")
	String sendDelayMsg(@PathVariable String msg) {
		rabbitTemplate.convertAndSend(delayQueue, msg);
		log.info("发送一条延迟消息：" + msg);
		return "success";
	}

	@RequestMapping("/direct/{msg}")
	String sendDirectMsg(@PathVariable String msg) {
		rabbitTemplate.convertAndSend("yangye-direct-exchange", "yangye-direct-routing-key", msg);
		log.info("发送一条普通消息：" + msg);
		return "success";
	}
}
